<?php
/**
 * Created by PhpStorm OF Administrator.
 * User: YUYI
 * Date: 2018/6/28 0028
 * Time: 上午 10:19
 * Administrator
 */

namespace app\admin\controller;


use app\common\controller\Base;
use app\common\model\Menus;
use app\common\service\LayuiListApiService;
use think\db\Query;

class Menu extends Base
{
    protected $getList = 'Menus';
    protected $getListWith = 'getSonMenu';
    public function index()
    {
        return $this->fetch();
    }

    public function detail($id)
    {
        $menu = Menus::get($id,['getParentMenu']);
        if (!$menu){
            return $this->errorInfo('非法访问');
        }
        $pmenus = Menus::all(['id'=>['<>',$id]]);
        $this->assign('pmenus',$pmenus);
        $this->assign('menu',$menu);
        return $this->fetch();
    }

    public function add()
    {
        $pmenus = Menus::all();
        $this->assign('pmenus',$pmenus);
        return $this->fetch();
    }

    public function save()
    {
        $m = Menus::create(input());
        if (!$m){
            return $this->errorInfo('新增失败');
        }
        return $this->successInfo('成功');
    }
}